import { IFeidaoAiBrowserComponent } from '@feidao/web/interfaces';
import set_node_cls from '@feidao/web/atom/browser/ui/set-node-cls';
import { anim, play } from '@feidao/animation';

export default async function (fd: IFeidaoAiBrowserComponent, ...args: any[]) {
	let d: any = null;
	const type = args[0][0];
	const info = args[0][1];
	const fail_div = fd.data.node.querySelector('[data-feidao-id="fail_div"]') as HTMLElement;
	const success_div = fd.data.node.querySelector('[data-feidao-id="success_div"]') as HTMLElement;
	if (type === 'success') {
		const prompt_sucess = fd.data.node.querySelector('[data-feidao-id="prompt_sucess"]') as HTMLElement;
		prompt_sucess.innerHTML = info;
		set_node_cls(success_div, 'display-n', false);
	} else if (type === 'fail') {
		const prompt_fail = fd.data.node.querySelector('[data-feidao-id="prompt_fail"]') as HTMLElement;
		prompt_fail.innerHTML = info;
		set_node_cls(fail_div, 'display-n', false);
	};
	// 滑出
	play(anim(fd.data.node, {
	}, {
			top: {
				start: -50,
				end: -10
			}
		}));
	d = window.setTimeout(() => {
		window.clearTimeout(d);
		play(anim(fd.data.node, {
		}, {
				top: {
					start: -10,
					end: -50
				}
			}));
		set_node_cls(success_div, 'display-n', true);
		set_node_cls(fail_div, 'display-n', true);
	}, 3000);
	fd.data.d = d;
}